package com.hou.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hou.commonutils.R;
import com.hou.eduservice.entity.EduCourse;
import com.hou.eduservice.entity.EduTeacher;
import com.hou.eduservice.service.EduCourseService;
import com.hou.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author shkstart
 * @create 2021-11-27-14:14
 */
@Api(description = "前端讲师")
@RestController
@RequestMapping("/eduservice/teacher")
@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private EduCourseService eduCourseService;

    // 分页查询讲师
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable Long page, @PathVariable Long limit) {

        Page<EduTeacher> teacherPage = new Page<>(page,limit);

        Map<String,Object> map = eduTeacherService.getTeacherFrontList(teacherPage);

        return R.ok().data(map);
    }

    // 获取讲师个人信息和讲授课程
    @GetMapping("getTeacherInfoById/{id}")
    public R getTeacherInfoById(@PathVariable String id) {

        EduTeacher teacher = eduTeacherService.getById(id);

        QueryWrapper<EduCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teacher_id",id);
        List<EduCourse> courses = eduCourseService.list(queryWrapper);

        return R.ok().data("teacher",teacher).data("course",courses);

    }


}
